﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace QuanLyThuNgan
{
    public class ThuDTLDAO
    {
         
       System.Data.SqlClient.SqlConnection cn;
       public ThuDTLDAO()
       {
        if (cn == null) cn=Uit.it_Conn.getConnect(DonVi_Khac.ConnectPhkham_S3);
       }
        
        public object m_Insert(ThuDTLDTO _info,int IDNguoiNhap,int IDCaThuNgan)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_Utb_ThuDtl_InSert_TamUng '{0}','{1}','{2}',{3},'{4}',{5},{6}", _info.Ssohs, _info.Ssonhapvien, _info.Sngaynop, _info.Fsotien,_info.Snoivao,IDNguoiNhap,IDCaThuNgan);
            return Uit.it_SQL.ExecuteScalar(_sql,null);
        }
        public bool m_Update(string sobn,float sotien)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_Utb_ThuDtl_UpDate_TamUng '{0}',{1}", sobn, sotien);
            return Uit.it_SQL.ExecuteNonQuery(_sql, false);
        }
        public bool m_Delete(ThuDTLDTO _info)
        {
            string _sql = string.Format("usp_ThuNgan_ThuDTL_Delete {0}", _info.Smaphieu);
            return Uit.it_SQL.ExecuteNonQuery(_sql, false);
        }

        public DataTable m_SelectAllThuDTL()
        {
            string _sql = string.Format("usp_ThuNgan_ThuDTL_SelectAll  ");
            return Uit.it_SQL.getDataTable(_sql, null, "");
        }
        #region "LeThanhDung-ThanhToanXuatVien"

        //load danh sach benh nhan thanh toan xuat vien----------------------
        public DataTable m_DSBNThanhToanXuatVien(string sohs, string ho, string ten, int namsinh, string sonhapvien, string traibenh)
        {
            string _sql = string.Format("exec dbo.usp_HIS_DM_BenhNhan_ThanhToanXuatVien '{0}',N'{1}',N'{2}',{3},'{4}','{5}'", sohs, ho, ten, namsinh, sonhapvien, traibenh);
            return Uit.it_SQL.getDataTable(_sql);
        }

        public DataTable m_ThanhToanXuatVien(string sohsxv, string sonhapvienxv )
        {
            string _sql = string.Format("exec usp_ThuNgan_ThanhToanXuatVien_Load '{0}','{1}'", sohsxv, sonhapvienxv);
            return Uit.it_SQL.getDataTable(_sql,cn);
        }

        //insert thanh toan xuat vien---------------------------------------------
        public bool m_InsertThanhToanXuatVien(ThuDTLDTO _info)
        {
            string _sql = string.Format(" exec usp_ThuNgan_Utb_ThuDtl_InSert_ThanhToanXuatVien '{0}','{1}','{2}',{3},{4},'{5}',{6},{7}", _info.Ssohs, _info.Ssonhapvien, _info.Sngaynop, _info.Fsotien, _info.Ifeeid, _info.Snoivao, _info.IIDNguoiNhap, _info.IIDCaThuNgan);
            return Uit.it_SQL.ExecuteNonQuery(_sql, false);
        }

        //In thanh toan xuat vien------------------------------------------
        public DataTable m_InXuatVien(string sohsxv, string sonhapvienxv)
        {
            string _sql = string.Format("exec usp_ThuNgan_BienLaiXuatVien_Load '{0}','{1}'", sohsxv, sonhapvienxv);
            return Uit.it_SQL.getDataTable(_sql);
        }

        //Danh sach xuat vien xuat vien------------------------------------------
        public DataTable m_DanhSachXuatVien(string sohsxv, string sonhapvienxv)
        {
            string _sql = string.Format("exec dbo.usp_ThuNgan_LoadDanhSachPhieuNopTien '{0}','{1}'", sohsxv, sonhapvienxv);
            return Uit.it_SQL.getDataTable(_sql);
        }
        #endregion
    }
}
